export default {
	//这里写的很垃圾，目前没想到好的办法，临时解决
    state: {
        images:[],
    },
    mutations: {
        setImages(state, data) {
			state.images = data
        },
		deleteImages(state,{
			url,
			msgindex,
			zuindex
		}){
			let index = state.images.findIndex(item=>{
				return item.url == url && item.msgindex == msgindex && item.zuindex == zuindex
			})
			if(index != -1){
				state.images.splice(index,1)
			}
		},
		pushImages(state, data) {
			state.images.push(data)
			//节流一下，避免频繁更新
			uni.$u.throttle(()=>{
				console.log(111);
				state.images.sort((a, b) => {
				    if (a.msgindex === b.msgindex) {
				        return a.zuindex - b.zuindex; // 如果 index 相同，按照 unindex 从大到小排序
				    } else {
				        return a.msgindex - b.msgindex; // 否则按照 index 从大到小排序
				    }
				});
			}, 200,false)
		},
    },
	getters: {
	    imageUrls: (state) => () => {
	        return state.images.map(item => item.url);
	    },
		imageUrlsIndex: (state) => ({
			url,
			msgindex,
			zuindex
		}) => {
			return state.images.findIndex(item=>{
				return item.url == url && item.msgindex == msgindex && item.zuindex == zuindex
			})
		}
	},
    actions: {
		
    }
};